#include <iostream>
#include <vector>
#include <algorithm>
#include <format>
using namespace std;
int main() {
  // id, s1, s2, rank, count;
  struct Info {
    int id, s1, s2, count;
  };
  int n;
  cin >> n;
  vector<Info> infos(n);
  for (int i = 0; i < n; i ++) infos[i].id = i + 1;
  for (int rank = n; rank >= 1; rank --) {
    int id;
    cin >> id;
    infos[id - 1].s1 = rank;
  }
  for (auto &info : infos) cin >> info.count;
  sort(infos.begin(), infos.end(), [](Info &a, Info &b) {
    return a.count < b.count;
  });
  for (int i = 0; i < n; i ++) {
    infos[i].s2 = i + 1;
  }
  sort(infos.begin(), infos.end(), [](Info &a, Info &b) {
    if (a.s1 + a.s2 == b.s1 + b.s2) return a.s2 > b.s2;
    return a.s1 + a.s2 > b.s1 + b.s2;
  });
  for (int i = 0; i < n; i ++) {
    cout << format("{}. Kod{:0>2} ({})", i + 1, infos[i].id, infos[i].s1 + infos[i].s2) << endl;
  }
}